package b.b.c;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.ActionMenuPresenter;
import androidx.appcompat.widget.Toolbar;
import b.b.g.f;
import b.b.g.g;
import b.b.h.n;
import b.i.k.o;
import b.i.k.t;
import b.i.k.u;
import b.i.k.v;
import b.i.k.w;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.WeakHashMap;

/* compiled from: WindowDecorActionBar */
public class r extends ActionBar implements androidx.appcompat.widget.ActionBarOverlayLayout.d {
    public static final Interpolator B = new AccelerateInterpolator();
    public static final Interpolator C = new DecelerateInterpolator();
    public final w A = new c();
    public Context a;
    public Context b;
    public Activity c;
    public ActionBarOverlayLayout d;
    public ActionBarContainer e;
    public n f;
    public ActionBarContextView g;
    public View h;
    public boolean i;
    public d j;
    public b.b.g.a k;
    public b.b.g.a.a l;
    public boolean m;
    public ArrayList<androidx.appcompat.app.ActionBar.a> n = new ArrayList();
    public boolean o;
    public int p = 0;
    public boolean q = true;
    public boolean r;
    public boolean s;
    public boolean t;
    public boolean u = true;
    public g v;
    public boolean w;
    public boolean x;
    public final u y = new a();
    public final u z = new b();

    /* compiled from: WindowDecorActionBar */
    public class c implements w {
    }

    /* compiled from: WindowDecorActionBar */
    public class d extends b.b.g.a implements b.b.g.i.g.a {
        public final Context c;
        public final b.b.g.i.g d;
        public b.b.g.a.a e;
        public WeakReference<View> f;

        public d(Context context, b.b.g.a.a aVar) {
            this.c = context;
            this.e = aVar;
            b.b.g.i.g gVar = new b.b.g.i.g(context);
            this.d = gVar;
            gVar.e = this;
        }

        public boolean a(b.b.g.i.g gVar, MenuItem menuItem) {
            b.b.g.a.a aVar = this.e;
            return aVar != null ? aVar.c(this, menuItem) : false;
        }

        public void b(b.b.g.i.g gVar) {
            if (this.e != null) {
                i();
                ActionMenuPresenter actionMenuPresenter = r.this.g.d;
                if (actionMenuPresenter != null) {
                    actionMenuPresenter.n();
                }
            }
        }

        public void c() {
            r rVar = r.this;
            if (rVar.j == this) {
                boolean z = rVar.r;
                boolean z2 = rVar.s;
                Object obj = 1;
                if (z || z2) {
                    obj = null;
                }
                if (obj == null) {
                    rVar.k = this;
                    rVar.l = this.e;
                } else {
                    this.e.b(this);
                }
                this.e = null;
                r.this.r(false);
                ActionBarContextView actionBarContextView = r.this.g;
                if (actionBarContextView.k == null) {
                    actionBarContextView.h();
                }
                r.this.f.k().sendAccessibilityEvent(32);
                r rVar2 = r.this;
                rVar2.d.setHideOnContentScrollEnabled(rVar2.x);
                r.this.j = null;
            }
        }

        public View d() {
            WeakReference weakReference = this.f;
            return weakReference != null ? (View) weakReference.get() : null;
        }

        public Menu e() {
            return this.d;
        }

        public MenuInflater f() {
            return new f(this.c);
        }

        public CharSequence g() {
            return r.this.g.getSubtitle();
        }

        public CharSequence h() {
            return r.this.g.getTitle();
        }

        public void i() {
            if (r.this.j == this) {
                this.d.z();
                try {
                    this.e.a(this, this.d);
                } finally {
                    this.d.y();
                }
            }
        }

        public boolean j() {
            return r.this.g.r;
        }

        public void k(View view) {
            r.this.g.setCustomView(view);
            this.f = new WeakReference(view);
        }

        public void l(int i) {
            r.this.g.setSubtitle(r.this.a.getResources().getString(i));
        }

        public void m(CharSequence charSequence) {
            r.this.g.setSubtitle(charSequence);
        }

        public void n(int i) {
            r.this.g.setTitle(r.this.a.getResources().getString(i));
        }

        public void o(CharSequence charSequence) {
            r.this.g.setTitle(charSequence);
        }

        public void p(boolean z) {
            this.b = z;
            r.this.g.setTitleOptional(z);
        }
    }

    /* compiled from: WindowDecorActionBar */
    public class a extends v {
        public void b(View view) {
            r rVar = r.this;
            if (rVar.q) {
                view = rVar.h;
                if (view != null) {
                    view.setTranslationY(0.0f);
                    r.this.e.setTranslationY(0.0f);
                }
            }
            r.this.e.setVisibility(8);
            r.this.e.setTransitioning(false);
            rVar = r.this;
            rVar.v = null;
            b.b.g.a.a aVar = rVar.l;
            if (aVar != null) {
                aVar.b(rVar.k);
                rVar.k = null;
                rVar.l = null;
            }
            ActionBarOverlayLayout actionBarOverlayLayout = r.this.d;
            if (actionBarOverlayLayout != null) {
                WeakHashMap weakHashMap = o.a;
                actionBarOverlayLayout.requestApplyInsets();
            }
        }
    }

    /* compiled from: WindowDecorActionBar */
    public class b extends v {
        public void b(View view) {
            r rVar = r.this;
            rVar.v = null;
            rVar.e.requestLayout();
        }
    }

    public r(Activity activity, boolean z) {
        ArrayList arrayList = new ArrayList();
        this.c = activity;
        View decorView = activity.getWindow().getDecorView();
        s(decorView);
        if (!z) {
            this.h = decorView.findViewById(16908290);
        }
    }

    public boolean b() {
        n nVar = this.f;
        if (nVar == null || !nVar.m()) {
            return false;
        }
        this.f.collapseActionView();
        return true;
    }

    public void c(boolean z) {
        if (z != this.m) {
            this.m = z;
            int size = this.n.size();
            for (int i = 0; i < size; i++) {
                ((androidx.appcompat.app.ActionBar.a) this.n.get(i)).a(z);
            }
        }
    }

    public int d() {
        return this.f.o();
    }

    public Context e() {
        if (this.b == null) {
            TypedValue typedValue = new TypedValue();
            this.a.getTheme().resolveAttribute(2130968586, typedValue, true);
            int i = typedValue.resourceId;
            if (i != 0) {
                this.b = new ContextThemeWrapper(this.a, i);
            } else {
                this.b = this.a;
            }
        }
        return this.b;
    }

    public void f() {
        if (!this.r) {
            this.r = true;
            u(false);
        }
    }

    public void h(Configuration configuration) {
        t(this.a.getResources().getBoolean(2131034112));
    }

    public boolean j(int i, KeyEvent keyEvent) {
        d dVar = this.j;
        if (dVar == null) {
            return false;
        }
        b.b.g.i.g gVar = dVar.d;
        if (gVar == null) {
            return false;
        }
        boolean z = true;
        if (KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() == 1) {
            z = false;
        }
        gVar.setQwertyMode(z);
        return gVar.performShortcut(i, keyEvent, 0);
    }

    public void m(boolean z) {
        if (!this.i) {
            n(z);
        }
    }

    public void n(boolean z) {
        int i = z ? 4 : 0;
        int o = this.f.o();
        this.i = true;
        this.f.n((i & 4) | (-5 & o));
    }

    public void o(boolean z) {
        this.w = z;
        if (!z) {
            g gVar = this.v;
            if (gVar != null) {
                gVar.a();
            }
        }
    }

    public void p(CharSequence charSequence) {
        this.f.setWindowTitle(charSequence);
    }

    public b.b.g.a q(b.b.g.a.a aVar) {
        d dVar = this.j;
        if (dVar != null) {
            dVar.c();
        }
        this.d.setHideOnContentScrollEnabled(false);
        this.g.h();
        dVar = new d(this.g.getContext(), aVar);
        dVar.d.z();
        try {
            Object d = dVar.e.d(dVar, dVar.d);
            if (d == null) {
                return null;
            }
            this.j = dVar;
            dVar.i();
            this.g.f(dVar);
            r(true);
            this.g.sendAccessibilityEvent(32);
            return dVar;
        } finally {
            dVar = dVar.d;
            dVar.y();
        }
    }

    public void r(boolean z) {
        if (z) {
            if (!this.t) {
                this.t = true;
                ActionBarOverlayLayout actionBarOverlayLayout = this.d;
                if (actionBarOverlayLayout != null) {
                    actionBarOverlayLayout.setShowingForActionMode(true);
                }
                u(false);
            }
        } else if (this.t) {
            this.t = false;
            ActionBarOverlayLayout actionBarOverlayLayout2 = this.d;
            if (actionBarOverlayLayout2 != null) {
                actionBarOverlayLayout2.setShowingForActionMode(false);
            }
            u(false);
        }
        ActionBarContainer actionBarContainer = this.e;
        WeakHashMap weakHashMap = o.a;
        if (actionBarContainer.isLaidOut()) {
            Object s;
            t e;
            if (z) {
                s = this.f.s(4, 100);
                e = this.g.e(0, 200);
            } else {
                e = this.f.s(0, 200);
                s = this.g.e(8, 100);
            }
            g gVar = new g();
            gVar.a.add(s);
            View view = (View) s.a.get();
            long duration = view != null ? view.animate().getDuration() : 0;
            view = (View) e.a.get();
            if (view != null) {
                view.animate().setStartDelay(duration);
            }
            gVar.a.add(e);
            gVar.b();
        } else if (z) {
            this.f.setVisibility(4);
            this.g.setVisibility(0);
        } else {
            this.f.setVisibility(0);
            this.g.setVisibility(8);
        }
    }

    public final void s(View view) {
        n nVar;
        ActionBarOverlayLayout actionBarOverlayLayout = (ActionBarOverlayLayout) view.findViewById(2131296494);
        this.d = actionBarOverlayLayout;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setActionBarVisibilityCallback(this);
        }
        View findViewById = view.findViewById(2131296307);
        if (findViewById instanceof n) {
            nVar = (n) findViewById;
        } else if (findViewById instanceof Toolbar) {
            nVar = ((Toolbar) findViewById).getWrapper();
        } else {
            StringBuilder g = c.b.a.a.a.g("Can't make a decor toolbar out of ");
            g.append(findViewById != null ? findViewById.getClass().getSimpleName() : "null");
            throw new IllegalStateException(g.toString());
        }
        this.f = nVar;
        this.g = (ActionBarContextView) view.findViewById(2131296316);
        ActionBarContainer actionBarContainer = (ActionBarContainer) view.findViewById(2131296309);
        this.e = actionBarContainer;
        nVar = this.f;
        if (nVar == null || this.g == null || actionBarContainer == null) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(r.class.getSimpleName());
            stringBuilder.append(" can only be used with a compatible window decor layout");
            throw new IllegalStateException(stringBuilder.toString());
        }
        this.a = nVar.getContext();
        Object obj = (this.f.o() & 4) != 0 ? 1 : null;
        if (obj != null) {
            this.i = true;
        }
        Context context = this.a;
        boolean z = ((context.getApplicationInfo().targetSdkVersion < 14 ? 1 : null) == null && obj == null) ? false : true;
        this.f.l(z);
        t(context.getResources().getBoolean(2131034112));
        TypedArray obtainStyledAttributes = this.a.obtainStyledAttributes(null, b.b.b.a, 2130968581, 0);
        if (obtainStyledAttributes.getBoolean(14, false)) {
            ActionBarOverlayLayout actionBarOverlayLayout2 = this.d;
            if (actionBarOverlayLayout2.h) {
                this.x = true;
                actionBarOverlayLayout2.setHideOnContentScrollEnabled(true);
            } else {
                throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
            }
        }
        int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(12, 0);
        if (dimensionPixelSize != 0) {
            float f = (float) dimensionPixelSize;
            ActionBarContainer actionBarContainer2 = this.e;
            WeakHashMap weakHashMap = o.a;
            actionBarContainer2.setElevation(f);
        }
        obtainStyledAttributes.recycle();
    }

    public final void t(boolean z) {
        this.o = z;
        if (z) {
            this.e.setTabContainer(null);
            this.f.j(null);
        } else {
            this.f.j(null);
            this.e.setTabContainer(null);
        }
        boolean z2 = true;
        Object obj = this.f.r() == 2 ? 1 : null;
        n nVar = this.f;
        boolean z3 = (this.o || obj == null) ? false : true;
        nVar.v(z3);
        ActionBarOverlayLayout actionBarOverlayLayout = this.d;
        if (this.o || obj == null) {
            z2 = false;
        }
        actionBarOverlayLayout.setHasNonEmbeddedTabs(z2);
    }

    public final void u(boolean z) {
        Object obj = (!this.t && (this.r || this.s)) ? null : 1;
        g gVar;
        int[] iArr;
        boolean z2;
        View view;
        if (obj != null) {
            if (!this.u) {
                this.u = true;
                gVar = this.v;
                if (gVar != null) {
                    gVar.a();
                }
                this.e.setVisibility(0);
                if (this.p == 0 && (this.w || z)) {
                    this.e.setTranslationY(0.0f);
                    float f = (float) (-this.e.getHeight());
                    if (z) {
                        iArr = new int[]{0, 0};
                        this.e.getLocationInWindow(iArr);
                        f -= (float) iArr[1];
                    }
                    this.e.setTranslationY(f);
                    g gVar2 = new g();
                    t a = o.a(this.e);
                    a.g(0.0f);
                    a.f(this.A);
                    if (!gVar2.e) {
                        gVar2.a.add(a);
                    }
                    if (this.q) {
                        View view2 = this.h;
                        if (view2 != null) {
                            view2.setTranslationY(f);
                            t a2 = o.a(this.h);
                            a2.g(0.0f);
                            if (!gVar2.e) {
                                gVar2.a.add(a2);
                            }
                        }
                    }
                    Interpolator interpolator = C;
                    z2 = gVar2.e;
                    if (!z2) {
                        gVar2.c = interpolator;
                    }
                    if (!z2) {
                        gVar2.b = 250;
                    }
                    u uVar = this.z;
                    if (!z2) {
                        gVar2.d = uVar;
                    }
                    this.v = gVar2;
                    gVar2.b();
                } else {
                    this.e.setAlpha(1.0f);
                    this.e.setTranslationY(0.0f);
                    if (this.q) {
                        view = this.h;
                        if (view != null) {
                            view.setTranslationY(0.0f);
                        }
                    }
                    this.z.b(null);
                }
                ActionBarOverlayLayout actionBarOverlayLayout = this.d;
                if (actionBarOverlayLayout != null) {
                    WeakHashMap weakHashMap = o.a;
                    actionBarOverlayLayout.requestApplyInsets();
                }
            }
        } else if (this.u) {
            this.u = false;
            gVar = this.v;
            if (gVar != null) {
                gVar.a();
            }
            if (this.p == 0 && (this.w || z)) {
                this.e.setAlpha(1.0f);
                this.e.setTransitioning(true);
                gVar = new g();
                float f2 = (float) (-this.e.getHeight());
                if (z) {
                    iArr = new int[]{0, 0};
                    this.e.getLocationInWindow(iArr);
                    f2 -= (float) iArr[1];
                }
                t a3 = o.a(this.e);
                a3.g(f2);
                a3.f(this.A);
                if (!gVar.e) {
                    gVar.a.add(a3);
                }
                if (this.q) {
                    view = this.h;
                    if (view != null) {
                        a3 = o.a(view);
                        a3.g(f2);
                        if (!gVar.e) {
                            gVar.a.add(a3);
                        }
                    }
                }
                Interpolator interpolator2 = B;
                z2 = gVar.e;
                if (!z2) {
                    gVar.c = interpolator2;
                }
                if (!z2) {
                    gVar.b = 250;
                }
                u uVar2 = this.y;
                if (!z2) {
                    gVar.d = uVar2;
                }
                this.v = gVar;
                gVar.b();
                return;
            }
            this.y.b(null);
        }
    }

    public r(Dialog dialog) {
        ArrayList arrayList = new ArrayList();
        s(dialog.getWindow().getDecorView());
    }
}
